Cleaned up the main file a bit and added some more logging.