Add comment and fix some logical issue