Take out window.app dependency and use filter() in update loop

This working probably is a sign of a leaking global (`i` ?)