Redid some of the logic.