Clean up source some

Split most of the lines that were over 80 characters
long up over several lines. Simplified a couple functions
by spliting them up into helper functions