refactor to make it more FP like