Fixed a few bugs such as exit throwing an exception