fixed minor bugs and refactored exit patterns