fixed bugs in reverse operation