Replaced a bunch of preprocessor directives with extensionmethods

That code should now be much easier to read