refucktoring: some dup code becomes function