Added error checking to samples