Fixed inifinite loop bugs and made pacman example work

See commit messages for details.