Remove a load of duplicated code.