add exception catching and relevant sorting