working implementation for PD1. Still requires commenting...