Added some tests, and error handling