Sort functions and add header comments