Implemented additional wellformedness checks, but some TODO statements record areas where further work is required.