add test and delete duplicate code