Fix tests + out of range panic (variable was used from an incorrect scope)