Code refactoring + separate density estimation from pi estimation