refactored code and removed preprocessor