fixed several tests, refactoring, etc.