An algorithm to improve consistency in Smoothed Particle Hydrodynamics