refactor add function