Upgraded reverse function