added sampling code