Omptised Problem 51 a bit, it still takes a couple minutes to execute, but it's better than it was.