Bug fixes. Also added some unit tests back to the restructured code.
Forgot to add some files.