Fix mismatch vector / array and some other bugs