rearranged code calls to fix potential bug