better error handling, unit tests