works, rewrite and simplify