refactor rec writer