Code cleanup and some fixes

Some cleanup and tests needed in order to be able to work on bnc#907907 with confidence.

Sorry for not separating in commits the zombie killing from the spliting into smaller methods, but the latter is very simple (just moving the code a little bit).

https://bugzilla.suse.com/show_bug.cgi?id=907907
can you point me to such statement? each_pair and each should be identical, so `sort.each_pair` should work