Fixed a lot of seg faults and infinite loops.

Current bug that I am tracking is some statements are not getting read, for example
line 4 of diag.out doesn't get added to the statements array, which causes a problem
since that is the line with the "Initial" keyword. I imagine it has something to do
with that line not ending in a semicolon. Investigate around terrain.cpp:69.