added a local to make variable stay in function