heavy refactoring of small_graph and small refactoring of static_matrix