added many new features and small refactoring