Added code for sampling states