Refactoring, deleted usless functions and changed the logic of some functions