Fixed bugs to pass the unit tests!