Making headway, pulling this stuff apart into separate functions.