Updated: First commit

Clearly not perfect, but thrown together to work. Needs lots of refinement, but it does currently work.