Who's legally responsible when the building burns down, or someone gets killed because of faulty wiring?

Texas Ranger mentioned that in his area the contractor is responsible for inspecting his/her own work. I'm not clear about the legal ramifications of that set-up. My thoughts are that it doesn't matter much whether a code of regulations is used, or a set of standards is used, so long as the contractor knows what needs to be done for safe practice (and I address this issue in my previous thread).
Without someone else looking over the work, and verifying that it is safe, then when the building burns down or someone gets killed, how is anyone to know who did the work? ..or know whom to blame? Anyone can come in after the contractor leaves, and modify or extend on the original wiring. Without some outside inspection process, how can anyone come back to the original contractor and take him/her to court over falulty wiring?