Can these common 5 lines be pulled out into a function for neatness?