Fix errors flagged by -Wall.
These resulted in segfaults when running in debug mode.
gcc is your friend!
Several Corrections
After Merge
Several fixes on previous work