+ refactoring some functions [need testing]