Fixed nested/spanned node issues

Fixes a number of issues with nested/spanned nodes and simplifies the regular expressions.