Refractoring Finished

Copying the code to the Working branch