There is a repeated pattern here. Is it worth a function?