I got rid of that massive if-block for you

I made your code a bit nicer to work with.

I don't have most of the right tools at hand right now, so I didn't have the opportunity to actually test it yet. Please do that first.