Added cleanup functionality and tests
Added the CLI logic
Fixed the errors not being reported to mocha