rewrite primitive implementations