Refactore and commented some of the code written