Minor Bug Fixes

Minor bug fixes and slight code reorganization
Added exit condition by saying exit