State variables, get-exitcode corrections. - SR

Changed all hard coded state values to variables, for sanities sake.
Corrected some issues with get-exitcode not altering exitcode despite matching conditions.
Minor spelling correction.