Tidying up dicts and code