initial commit after major rewrite/refactor, near fully tested