Fixing bug found by tests