bug fix in reverse.py