Time to refactor some code and get rid of some duplication.