Fixed wrong loop control.
Removed dead code.