Structure definition functionality, and tidying up of code.

Structure definition functionality, and tidying up of code