refractored code and removed unneccesary code