working code

Squashed remaining bugs.
All works as designed