cleaned up code which makes sure stimulus index is in range for some of the datastore methods