Unit tests and error handling