done with pre sorting