Fixed some bugs and improved the Dirichlet extension so that it is more stable.