major refactoring, fixed history support