fixed a few bugs; added a more tests