can simplify that a bit, avoid a global var