style improvement: consolidated type-specific code into one switch, added a few implicit semicolons