refactor code out of __init__.py, store undo history in :history, add some rest API