more efficient minimum calculation