renaming and refactoring, using np.nanmin instead of array.min