Comments are added. The names of variables are updated, and a memory leak is fixed. The loop over weights is removed.