some minor tidying-up. still not found the bug.