added sampling code - still needs testing