code style, added comments
added test cases