fixing some bugs with density estimation, unclear if they are fixed yet