Sort statuses in right order and formatting code