working version, uses rules.txt