improved /complicated design to avoid duplicate code