Fix 'data' being referenced before assignment