better implementation of sampling grains