optimised coocurrence code