Some tidying up to make the code actually work