fix(modal): check before removing element (fixes #343)