Cleaning up the code, trying to resolve the issue with 'cat' hanging