Refactor out some of the ugly