adjusted for ascii entities and fixed bugs in the switch statement.