First version of looping support implemented

Part of work for #96