add sort mechanism to tables & some fixes