Moved error handling to exit_program. Refactored operation order handling.