implemented GetDensity function