clean up duplicated code