fixing bugs and adding more tests