Added fiting logic.

And this time around it is actually sensible, and not totally baroque.