replace flatten() by ravel(), and minor changes