cleaning up and rewriting