Fixed loop protect when label is used

Fixes #1293 and includes tests.