fixing #290, In rare situations duplicate points in pointlist, and minor refactoring and test changes necessary