refactor to single function