more or less finished rewriting stuff