Added some semblance of unit testing -- found a few errors, too.