-mrefactored and make sorting working