Refactored some code. And further fixed the grid lines with some preprocessor magic.