GLM: Rewrite interactions module and update glm.c to use it in some places