Refactor duplicate processing to the same variable