some refactoring and removed old code