handle failed commands, return actual exit code. fixes #4

This is a rebase of #5 so that it includes the proper CI tests