added more tests, fixed several bugs