fix issue where rindex may return nil