fixing bugs with tests