Reorganized the code such that elements are grouped by type.