clean and change order of loops (reduced basis space)