Refactoring

some code improvements