Simplify codes using delegate