implementing sort