some cleanup and rewrite setup