Major rewrite

Many changes. test.pl is the file to work on. Will clean things up on
Monday.