Correctly handling negative indices