major refactor (partial)