Some work done with the main loop
New/dealloc code