Rework contract and add a fail function