More checks to make sure nesting level doesn't go below zero.  Issue #523.