Practically working RDPNFA.java. Needs more testing.