Optimize specialists local marker

Replace unconditional 'for loop' with conditional 'while loop', script exits when it's job is done now.