restructure code to use member variables