tweaking minmax implentation