Adding new method to make maxvalue more efficient