functions rearranged to have more logical names