Fixed fast flicker bug and converted code to C++.