rewrite with thunks