Optmization of addControl / queue sorting

Rewrite a bit of code to avoid looping thru all controls already in the
queue each time an element is added.
Then sort the queue just before validating the controls in it based on
the depth of the elements.