moved density estimation to factored to prevent compilation errors.