major refactor (not yet functional)