Refoctor some methods and Add sorting. Close #7