refactor by FP to reduce code for value