adding sampling function