refactor to improve performance