code cleanup and refactoring in apply_actions
fixes a bug: shproc not created when only ssh moves to do over ssh.
Thanks Airwan for finding it!