Bug fix in fail function