Main Loop

Need to merge with development.