add function, remove duplicate logic