fixed the "off by one" bug