Modifications to sampling function