added some test and fixed bugs