refactoring

some refactoring of the code.