Remove case statement

by using functions instead of case statement

- remove level of indentation
- allow use of local variables via "local" keyword