modify reverse method
a little refactoring