Added weight writing function.