First pass
Refactor out some duplication
Add other required files.