Fix edge cases when adding missing curly braces

Closes #37