refactoring code for improved readability and management