Reworked guard comparison

This is just a re-PR of accidentally closed #2015.