do some refactor of source
add some error tests
add more tests