Bug fixes for BP calculation and template registration.