Improve comment sorting and type handling