finished sort functions, fixed refresh bug