cleaned up run function