Could we move line 25 to 27 and 31 to 33 in one method to avoid duplicate code?