Isolating common functionality into functions