[PD-dev] refactoring pd~ to avoid deadlocks