Added infinity check in min and max