Refactored and cleaned up and cmake macros