more refactoring to make things more generic