fix error handling
add tests