improvments to the algo