Moved error handing outside the flasah driver