I admit I don't quite follow the logic after this point in the function.