Some refactoring, added history