Fixed a couple of memory leaks
Trivial refactoring for more consistent error reporting