sorting functionality in place