Added support for selecting weight_fractions

some minor improvements
keep an eye on that SUM function... it may be buggy
more thorough validation implemented
simplified writing layers in xml