fixed d being 1 all the time