Move library code to library.
Fix `run` to return the modified record.