refactor to functional