fixed issue with environment queue + misc refactoring