Optimize some PDM code.