fixed some bugs introduced during last refactoring