This is some ugly code and needs some more in depth refactoring.

Somewhere in the future. I guess.