Fix instruction generation bugs