Adding failed count check and some test refactoring