change the code to C++ way; frame rate detection