Move the preparing out of the loop