Cleaned the code. Fixed PD stuff