main loop logic, swap ins