Edited to take advantage of switch tables.