Moved some helper functions around