Added comments.
Removed whitespaces.
Changed stacked if if-then-else for switch-case.