Add comment and do minor refactoring