finished writing update weights function