More tidying up and bug-fixing.