Fixed a segmentation fault when no commands were entered (user just hit enter). Also lots of code cleanup.