further improvement in selection of best solution
code cleanup and comments addition