ported code to c++11