clean up code by emulating perl's 'die' command