fix some bugs, add modularity function.