Tweaks to triggers implementation. Use caching (dangerous but necessary as performance is terrible otherwise)