everything looks fine for n=10, so I'll try to figure out what's wrong with n=1000