fix off by one issue