add lots of error checking
raise exception in error case
add BSD license