restructured code and water number dens are calculated on the fly