changed implementation to avoid an os.Exit (it returns an error instead)