General refactor

Applied some composed method fu to extract duplication into smaller methods.