fixing logic error. adding more tests