Moved a few function to the top of the file