Some minor cleanups and more changes towards implementing looping