improves error handling, tests, validation