Rewrite with UI

Added some UI, rewriting algorithm