Tidying up and bug-fixing