Fixes to script reader

The input is now less sensitive to formatting erros and #+ format both
ends and starts a new chunk.