fixed an order of operations bug