Added comments and minor refactors.