implementing minkey and maxkey