Refactoring; move sys.exit to main function.