fix bugs to pass Unit test