Move import under app routes and enhance key handling