bug fix by Haiwei Zhou (off by one)