minor refactoring and fixed some failing unit tests