Cleaning up main. Move logging and fails outside of main.