Extract span handling to a method