Added quite a bit more intelligence.