density refactored