Fixing order of operations bug