DEBUG fixing variable scope