First loop goes fine but second loop fails