improved assign algo