Some tests covering failure cases
Moved error handling