changed code for on error