Fixed comparison function