WIP unit tests + any bug fixes found during.