Improving main method.
SOme cleanup.
Move partitioning logic to a separate class/interface.