Fix exception when trying to reference undeclared k