Move to a separate file, wrap in a function, update doc