added on-fail function as alternative to redirect