refactoring looots of code