Moved environment creation inside if-statement, no need to create it every time when it's used only once.