Cleaning API, Adding substructure support, reimplementing document api