move set() outside of loop