Cleaned up max-finding functions