bunch of improvements to improve loop closures