Refactor

Merging in some changing to remove duplicate code. Gotta get that 4.0!