This work follows from the recent discovery that genes involved in short-term memory also affect distractibility and persistence in the fruit fly. While the cognitive abilities of a fly are far from our own, the tools with which to study their basis are extremely powerful. Therefore, we will use a combination of virtual reality techniques, advanced molecular genetics, and control theoretic modeling to characterize and map the neural circuits involved in combining individual reflexes into large-scale structured behavior. Together with other work in the field, the results will show in an unsurpassed level of detail how the fly, with a brain smaller than a poppy seed, is successfully able to avoid danger, find food and mates, and navigate its world. The results may be useful both in understanding our own minds and for building machines inspired by the impressive capabilities of a fly.