figured out event listener approach, now need to fix race conditions