improved tests and error handling
improvements and tests