fix some problems with general case and columns selection, and
refactoring
added comments