fixed code errors and make the unit tests pass