extra credit: avoid using global variable