Use more modern style for variable declaration. The loop variable `i` should be declared in the for statement and I would rather see `density` declared closer to where it is actually used.