Add to_dict method and add a bunch of tests for it