function for finding maximum values