Sort and group imports