Function reverseIfNeeded