Maybe I'll create a thread later about that problem but for now it would be nice to just improve this part of the code a little.
If you are talking about the functions that find min/max, those are coded pretty much as I would. I don't know of a better or faster way.
I think something else is slowing the program down, whatever "slow" means. You haven't answered the question about how long is "a long time".