Cleanup, error handling, more tests