implemented a function for sorting fix #4