Added a result check as contract.
Added a rewind function.