misc code refactoring