tidying and fixing minor bugs.