Sexual imprinting as a two-stage process