improve error handling
add integration tests