refactor main expr function