Fixed the bug with returning the greatest element.