Small bugs and adding tests.