fixed stop() function to report correct exit code