Write PPM function 100% working