Bug fix according to unit tests