replaced buggy hard to read function processRule