upgraded logic