changed the location of some code to a better place