fixed some bugs introduced by refactoring