extract apply logic into a separate class