final code without update command and weights