fixed the code and updated the tests