Selectivity and energy recovery in capacitive deionization