Need to factor implementation-specific stuff out and better document and figure out appropriate types for arguments.