function reverse() completed