Small fixes to modularity function (still undergoing)