Fix for invalid index