On the evolution of sex determination