Using if instead of while for returning single records.