Improved coding style and added some unit tests