Added more specs and fixes for error handling