An improved SPH scheme for cosmological simulations