I have rearranged the functions in a more logical order, IMHO.