rearranged functions to make more sense