somewhat unflattening the pyramid of doom to preserve local scope