Cleaned up my last hack into maintainable code.

And it even works!!! :D:D:D