removing duplicated functions using switches