Implement priority based clearsnippets.

Implement priority-based clearsnippets and add corresponding test cases (#335).
this method looks very copy&pasted. Pull out a helper method that is local to this file?