Refractored code and reorginized