Fixes #4670
refactor code
added testRemoveMethodInsensitive
Merge pull request #5567