add some error handling code
add tests