Including the White Space, you have 918 lines of code and none of it is documented.
Steps 1 and 2 would be to document the code and add print statements to each section of the code to identify the section and how long that section of code actually took to run. "Divide'n'Conquer" is one of the main keys here because as the old saying goes, "Correct identification of the problem is 90% of the solution".
--Jeff Moden
Change is inevitable... Change for the better is not.