fixed coding style, added testcases, minor code fixes

Signed-off-by: Chirayu Chiripal <chirayu.chiripal@gmail.com>