Fix logic in in_degrees function