Complete rewrite

Mostly completed and a good time to merge into master to finish, test inside an app, and polish.