Refactor out some common error checking.
Actually compute #claimed and #free.