Change code according new diagram