Fix environment error and removed no longer used functions