fixed context and undifined index issues