Moved a bunch of useful functions out of random places