more refactoring... exit function works.