fixed uninitialized value bug
improved readability in switch statements, other minor cleanups