Refactor fn to lambda