Remove global state from loop