Problems executing loop