Refactoring the code from appendString to initString