fixed bugs which were introduced by refactoring