add checks on number of frees remaining and raise errors if it goes wroong