moved variables out of global scope