Avoid global data

Do not use global data. Use local variables instead of member variables where they are only used in one function.