partialy implemented P3
implemented P3 and small changes to P1 and P2
small improvements