Added some unit tests and fixed code style.