improved algo