Remove some variable setting logic duplication