fix error handling error
fix possible reference before assignment