Fix failed unit tests

    Also clean up a bit.