minor refactorization and cleanups