Continued refactoring progress (still not tested to work)- incorporate Mandar's improved handling of grep command, plus more graceful error handling