Modifying code for contextId generation