Rewritten to new api.