Fix merging algorithm
Add exit command when a command fails