Implement czchen-10404
Several bugs fixed
Fix off-by-one issue
Merge branch 'czchen/10404'

* czchen/10404:
  Fix off-by-one issue
  Several bugs fixed
  Implement czchen-10404