completed refactoring of matt hassel code