updates to the algorithm based on Vlad's feedback