tutorial. fix bugs and unit test