Added more unit tests and fixed a few minor bugs.