fix reference before assignment error