correct logic bug for density