Reorder functions and clean up syntax