Fixed hang when encountering unclosed block (and improved eof handling)