Added basic looping code

Still work in progress.