refactored for better logging, as well as command line options