working out the logic