Some refactoring and housekeeping.
Refactor switch statements. Adjust styles.
Update the documentation and todo list.