Convert reverse array iteration to a more elegant solution