Improve error handling
Improve tests