Gave functional fixes & removed unnecessary code. Also added few testcases