Some comments and refactoring
Comments and minor refactoring