Improve code style
Add some unit tests