Added reversing algorithm