rearranged some things to group items logically and put the meatier functions at the top