Fixed an issue with density, added a test and re-documented it.