python: add save function
r: restructure for sub-indexing, not working yet