optimize density function by storing density of parent path
refactor stuff. try random weights.