More tidying up and bug fixes.