Written more unit tests. Some other edits.