fixed bugs: Breaks in two loops.