This code still has the wrong normalization, but I've changed variable names and added comments for clarity