Put duplicate code into functions