rearranged operations in an attempt to improve speed