fix handling of minimum value, add comments

this fixes couple of problems with minimum handling, adds some comments, minor cleanup