More unit testing, a few fixes