Implemented CPP version