refactoring and improvements in code organization