Cleanup and exception handling
Closes #1
Closes #2