Complete port of C++ to D for K2 for POP