Extract duplicated code into common module