Speed up. Bounds checking in C++ side