result might be something besides 1, but is still bad.
Add some debugging statements, also return an exit on exit.