Completely working. Added sorting logic using Treesets