fixed "out of range" bug