Put loads of repeated code in a loop, saved about 500 lines