Reorganize function definitions