Replaced python script with faster C++ version