rearranged a few functions