added string length safety