fixed grep and sort bugs