Fix bad name recording, code cleanup, right exit codes

Not tested with zsh. Under bash seems to be working.
Merge pull request #2 from Totktonada/little-fixups

Fix bad name recording, code cleanup, right exit codes