Correctly escape strings when encoding
Handle more edge cases with discards and comments