fixed some bugs appearing from previous refactoring