refractored code to use properties rather than global ivars