Code cleanup

Remove switch statement and improve readability.