Moved some utility functions around