some miscellaneous refactoring