rearranged the elsif blocks