creating closures to protect variables