Use a for loop instead of duplicating the code for both keys