Tidying up and bugfixes.