Thursday night work

Mostly complete refactor. Missing named function.