refeactored code to ensure it complies with microsoft guidelines