added inplace sorting function