Adding exception handling
Adding flushing for new file outputs
Fixing bundlelines line replacement bug