Fixed sort and comparions functions. Tested working