cleaning up some logging and code indentation and moving things around