Added more tests, added error handling