Refactor signal handling for run command

Merged Kamil Trzcińśki requested to merge handle-signals into master