Made d fixed instead of variable. That fixes some issues.