Refactoring density map code.
Refactoring density map code.