modify stock algorithm