fixed erroneous if else ordering