refactor using pipeline and immediate anonymous function