conditional refactor

refactored all the redundant code, by using a if statement rather than
a switch