fixed tests, improved error handling