a lot of changes to make it arxiv ready