fixed the reference before assignment problem