Fixed the paneling algorithm to be better.

Previously I did something stupid, now it is less stupid.