Fixed found bugs and added more cases.