Implements reverseString method