Updated to use exceptions.