working on refactoring the code