Fixed bugs in variable setting