initial work with rewriting. I hate this shit