import code cleanups from adaptive branch