Reorganize code so there is only one return.