Some changes for running in QE env. Code cleanup.