modify function to select best split point