fix rounding issues and take density into account