upgraded grep4j logic