Move exit into function