Added comments & did some minor refactoring