moved stuff to run function