* reduce complexity by using switch instead of if else
* merge duplicated code into one method