Simplify/improve Application.instances, use flatMap instead of map