stem function bug fix