First working version

Functionally complete -- missing comments and formatting