1. env var order fix
2. refactoring