Fix the reference before assignment bug