adding tests, fixing bugs