fail function is now called when a error occours