fixed sampling function