Rich D: Small code cleanup tweeks
Rich D: refactorings
Rich D: more refactoring
fixed merge conflict, I thinkn