Fixing a variable reference error