Moving addClass('failed') as suggested in PR #1839