fixed potential memory leak when exception is thrown
added missing break statements
reduced variable scope
more STL-like names
initialized
removed unused variables