Refactor the code of functional lang