cleaning up the code, refactoring