fixed one-tick bug. Implemented c++