More ray index fixes. Still don't know if this is right though.