Replace home-made function.