Fixed minmax bug