fix inconsistent length checking vs indices usage