Implement order by feature
Cleanup code