cleaning up a lot of the duplicate code