Refactoring
Fixed sorting bug