Complete rewrite for the most part. Lots of changed. Partially working.