Add looping functionality. Unstable currently