rearranged code for readability