Code cleanup. Improved readability with better variable names. Removed unused variables. Shouldn't actually change anything about how Civi works.
Replaced hardcoded contribution status ID with a pseudoconstant lookup.
Variable $className was undefined; replaced it with a lookup for the class name of the current form.
Fixed misnamed variable. Should result in more useful error messages.
Whitespace edit for code readability.
Added some code documentation to help with debugging.