Updated to work with exceptions.