Yank several lines of kopipe. It bugged me.

Copy-pasta tastes better shared between two! :meat_on_bone: 

It bugged me when I saw it a while ago, so I decided to:
 - Share the common part of the (large) functions
 - Elided a now-unnecessary variable declaration
 - Changed an inner "break" on a condition inside a loop (where the condition could not vary within the loop body) to an opposite condition enclosing the loop.
 - Replaced ```for-each(x): contains x -> remove x```-type construct with removeAll

It's really not a 'constructive' commit, is it? :)