tightened up code by refactoring.