Reorder function to prevent not defined error