fixed reference before assignment issue