move clear() out of for loop