Maximize given code to expand string