Fix bad name recording, code cleanup, right exit codes

Not tested with zsh. Under bash seems to be working.