removed unused code and small refactoring