Rewrite of most of the base code. Much cleaner.