fixing up the code, refactoring