Algorithm rewritten. Improved handling for ListBoxes. Added textlogging.