Ellipsoidal collapse and an improved model for the number and spatial distribution of dark matter haloes