Refactor code to fit with functional programming paradigmats