Effects of the market factor on portfolio diversification: the case of market crashes