Split build_element function into smaller pieces