fixed bugs after huge refactoring