Corrected handling of strings containing quotes; grouped two code blocks in a single function.