Clean and reorganise list generator code