Bug789 v1 part1

This is the first part of the work on bug 789. It features some light cleaning in suricata main code.