added further tests and improved error handling