refactor using functions