speed-up max_degree() subroutine