reworked to switch statement

and some refactoring