Fixed the duplicated name bug, and added some unit tests