Fix errors and tidy-up