fix order of operations