some refactoring started for more modular code