This is another function that should be changed to raise exceptions if it can't do its work.  Then it can simply return three values (which is already feeling like too many values to return from a function).