Fixing write value to var function