fixed various bugs introduced with refactoring