refactor to use function chain