Fix exiting the shell, and fix a mem leak. Closes #54