first stab at a complete refactor