Additional refactoring, extracting common parts