remove hardcoded pin number
reduce number of global variables