refactoring and extracting types