Added provided code from paper (threshold isn't a thing yet)