Added middleware metadata and conditional environment loading.