order of operations bug fix