Add unit tests and address review comments.