more refactoring of code