added sampling function