Implemented RED, PPD and EPD.

Also, a few corner cases were handled.
RED, PPD and EPD were not properly verified.