added exit value checking