rearranged the order of some functions