replace exits with exceptions