Ported new pacman code from testing branch