safeguard against outofbounds array idx