fixing prolog loop