changes in code, addition of stratify function