Fix lots of heredoc parsing bugs (needs cleanup)