changed script such that it runs on one dataset at a time in order to reduce memory allocation