using defer.succeed & defer.fail (thanks @jerith)