some refactoring of code