Move all this stuff to a setState function