Some added comments and slight refactoring