Failed handling improvements and fixes

This code will improve and fix the failed handling.