Generic Failure function and miscellaneous bugs