Better grepping

TODO: need to go over this entire script