Moved logging up closer to start and use streamhandler instead of print.