Move this code to a function that has a name revealing its purpose; its unclear what this code does from a first look.