added string boundary check