refatcored some code