More code cleanup. Implemented sorting for grid