[PATCH] update_needed(): merge the same code into the function