Bug fix: infinite loop